const pupperteer = require("puppeteer");
const url = "https://www.duitang.com/";
async function getHomeData() {
    const browser = await pupperteer.launch({

    })
    const page = await browser.newPage();
    await page.goto(url, {
        waitUntil: 'networkidle2'
    });
    await page.waitFor(1000);
    await page.hover('body')
    let res = await page.evaluate(() => {
        var $ = window.jQuery;
        var items = $('.dynamic-feed-item,.dynamic-atlas,.hasExposure');
        var links = [];
        if (items.length > 0) {
            items.each((index, item) => {
                var userPic = $(item).find('.feed-container .user-info a img').attr("src");
                var userName=$(item).find('.user-info .user-desc .username').text();
                var imgUrl = $(item).find(".dynamic-multi-img-container img");
                var urls = imgUrl.map((index,item)=>{
                    return $(item).attr("src")
                })
                var id=$(item).attr("data-id")
                links.push({
                    id,
                    userPic,
                    userName,
                   urls:[...urls]
                })
            })
        }
        return links
    })

    browser.close();
    return res;
}
module.exports = getHomeData